<#include "../inc/view.html"/>
<@view>
            <form id="leaderAddForm${nowtime}" name="leaderAddForm" class="form-horizontal" action="/admin/leader/save" method="post" data-validator-option="{theme:'yellow_top'}">
                <input type="hidden" name="leader.id" value="${(po.id)!}">
            <div class="row">
                <div class="col-sm-6">
                    <ol class="breadcrumb">
                        <li>
                            <b>内容管理</b>
                        </li>
                        <li>
                            <a href="javascript:void(0);" onclick="contentLoadPage('/leader')">领导</a>
                        </li>
                        <li class="active">
                            <#if po??>修改
                                <#else>新增
                            </#if>
                        </li>
                    </ol>
                </div>
                <div class="col-sm-6">
                    <a onclick="contentLoadPage('/leader')" class="btn-sm btn-white pull-right" style="margin-left:10px;"><i class="ti-arrow-left"></i>返回</a>
                    <button type="submit" class="btn-sm btn-success pull-right"><i class="ti-save"></i>保存</button>
                </div>
            </div>
            <hr>
                <div class="row">
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="col-md-2 control-label">姓名</label>
                            <div class="col-md-10">
                                <input type="text" class="form-control" name="leader.name" data-rule="姓名:required" value="${(po.name)!}">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="col-md-2 control-label">头像</label>
                            <div class="col-md-10">
                                <input type="text" class="form-control" name="leader.img" id="leaderImg${nowtime}" data-rule="头像:required" value="${(po.img)!}">
                                <div>
                                    <!--用来存放item-->
                                    <div id="fileList${nowtime}" class="uploader-list pull-left"></div>
                                    <div id="filePicker${nowtime}" class=" pull-left">选择图片</div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="col-md-2 control-label">职务</label>
                            <div class="col-md-10">
                                <input type="text" class="form-control" name="leader.job" data-rule="职务:required" value="${(po.job)!}">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="col-md-2 control-label">简介</label>
                            <div class="col-md-10">
                                <textarea class="form-control" name="leader.summary">${(po.summary)!}</textarea>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="col-md-2 control-label">排序</label>
                            <div class="col-md-10">
                                <input type="text" class="form-control" name="leader.sort" value="${(po.sort)!1}">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="col-md-2 control-label">状态</label>
                            <div class="col-md-10">
                                <label><input type="radio" name="leader.status" value="1" <#if 1==(po.status)!1 >checked</#if> /> 启用</label>
                                <label><input type="radio" name="leader.status" value="0" <#if 2==(po.status)!1 >checked</#if> />禁用</label>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
</@view>
<script>
    $(function(){
        ajaxForm($("#leaderAddForm${nowtime}"),function(json){
            if(json.code==RESULT_SUCCESS){
                contentLoadPage('/leader');
            }else{
                if(json.msg)
                    layer.alert(json.msg,{icon:5,title:'系统提示',shadeClose:true});
            }
        });
        var $list = $('#fileList${nowtime}'),
            // 优化retina, 在retina下这个值是2
                ratio = window.devicePixelRatio || 1,

            // 缩略图大小
                thumbnailWidth = 100 * ratio,
                thumbnailHeight = 100 * ratio,

            // Web Uploader实例
                uploader;

        // 初始化Web Uploader
        uploader = WebUploader.create({
            // 自动上传。
            auto: true,
            // swf文件路径
            swf: '/s/plugins/webuploader/Uploader.swf',
            // 文件接收服务端。
            server: '/admin/file/upload4UE?action=uploadimage',
            // 选择文件的按钮。可选。
            // 内部根据当前运行是创建，可能是input元素，也可能是flash.
            pick: '#filePicker${nowtime}',
            // 只允许选择文件，可选。
            accept: {
                title: 'Images',
                extensions: 'gif,jpg,jpeg,bmp,png',
                mimeTypes: 'image/*'
            }
        });

        // 当有文件添加进来的时候
        uploader.on( 'fileQueued', function( file ) {
            var $li = $(
                            '<div id="' + file.id + '" class="file-item thumbnail">' +
                            '<img>' +
                            '<div class="info">' + file.name + '</div>' +
                            '</div>'
                    ),
                    $img = $li.find('img');
            $list.append( $li );
            // 创建缩略图
            uploader.makeThumb( file, function( error, src ) {
                if ( error ) {
                    $img.replaceWith('<span>不能预览</span>');
                    return;
                }
                $img.attr( 'src', src );
            }, thumbnailWidth, thumbnailHeight );
            uploader.upload();
        });
        // 文件上传成功，给item添加成功class, 用样式标记上传成功。
        uploader.on( 'uploadSuccess', function( file,response) {
            $( '#'+file.id ).addClass('upload-state-done');
            $("#leaderImg${nowtime}").val(response.url);
        });
        // 文件上传失败，现实上传出错。
        uploader.on( 'uploadError', function( file ) {
            var $li = $( '#'+file.id ),
                    $error = $li.find('div.error');
            // 避免重复创建
            if ( !$error.length ) {
                $error = $('<div class="error"></div>').appendTo( $li );
            }
            $error.text('上传失败');
        });
        // 完成上传完了，成功或者失败，先删除进度条。
        uploader.on( 'uploadComplete', function( file ) {
            $( '#'+file.id ).find('.progress').remove();
        });
    });
</script>